package mo.tags.recursion;

import mo.common.ListNode;

public class L24 {

    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode next = head.next;
        ListNode nextNext = next.next;
        next.next = head;
        head.next = swapPairs(nextNext);
        return next;
    }

    public static void main(String[] args) {
        L24 test = new L24();
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        ListNode res = test.swapPairs(node1);
        System.out.println(res);
    }
}
